# -*- coding: utf-8 -*-
from telnetlib import Telnet


def check_ip_for_telnet(ip, port):
    icnt = 0
    timeouts = [2, 3, 5]
    while True:
        try:
            with Telnet() as tn:
                tn.open(ip, port=port, timeout=timeouts[icnt])
            return 'ok'
        except Exception as ex:
            if icnt >= 2:
                return 'failed'
        icnt += 1